﻿
#region
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Collections;
using System.Data;
using System.Data.OleDb;
#endregion

namespace DAO
{
    public class HoaDonDAO : Dataprovider
    {

        #region Phương thức
        // khoi tao lop.
        public HoaDonDAO()
        {
        }

        // lay danh sach hoa don
        public ArrayList getDsHoaDon()
        {
            connect();
            string query = "SELECT * FROM HOADON";
            adapter = new OleDbDataAdapter(query, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);

            return arr;
        }

        // lay du lieu dua vao dataRow.
        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            HoaDonDTO hd = new HoaDonDTO();

            hd.MaHoaDon = dt.Rows[i]["MaHoaDon"].ToString();
            hd.MaKhachHang = dt.Rows[i]["MaKhachHang"].ToString();
            hd.MaNhanVien = dt.Rows[i]["MaNhanVien"].ToString();

            return (object)hd;
        }

        // them hoa don moi
        public void insert(HoaDonDTO info)
        {
            string insertCommand = "INSERT INTO HOADON VALUES('" +
                info.MaHoaDon + "', '" +
                info.MaKhachHang + "', '" +
                info.MaNhanVien + ")";

            executeNonQuery(insertCommand);
        }

        // xoa hoa don
        public void delete(string maHD)
        {
            string deleteCommand = "DELETE FROM HOADON WHERE MaHoaDon = '" + maHD + "'";
            executeNonQuery(deleteCommand);
        }

        #endregion
    }
}
